/**
 * 医疗服务质询初始化模块，提供医疗服务编辑页面初始化组件功能
 * 
 * @Date: 2016-1-25
 * @author: Jackson wang
 * @version: 1.0
 * @since: 1.0
 */

define(["jquery","sysmanMain","valueUtil","datagridServ","formServ"],
		function($,sysmanMain,valueUtil,datagridServ,formServ) {
			
		'use strict';
		
		var rootid = 'panel-satisfaction-inpatient-dept'
		
		var window_id = 'satisfaction-inpatient-dept-window'
		
		var public_method ={
			
			
			initElement:function(_options){
				var rootid = _options.rootId
				var _startDate = $('#' +rootid+' #evaluate_time_start')
						
					var _endDate = $('#' +rootid+' #evaluate_time_end')
					if(_startDate.length>0){
						var curDate = new Date();
						
						var _tmp = valueUtil.getDateValue({source:curDate,format:'yyyy-MM-dd'})
						$(_endDate).datebox('setValue',_tmp);							
						
						
						curDate.setDate(1);
						
						_tmp = valueUtil.getDateValue({source:curDate,format:'yyyy-MM-dd'})
						$(_startDate).datebox('setValue',_tmp);
					}
			},
			
			/**
			 * 设置模块点击页面
			 * @param _options.record 列表选中行
			 * @param _options.grid 页面form对象
			 * @param _options.rootId 页面根节点
			 */
			clickCell:function(index,field,value){
				
				var _config = sysmanMain.getCurrentModuConfig()
				
				
				_config.clickValue = 1
				sysmanMain.setCurrentModuConfig(_config)
				
				var _param ={}
				if(field && (field!=='cnt')){
					_param.issue = field
				}				
				
				_config.clickParam = _param				
				sysmanMain.setCurrentModuConfig(_config)
				
			},
			
			/**
			 * 设置模块点击参数页面
			 * @param _options.record 列表选中行
			 * @param _options.grid 页面form对象
			 * @param _options.rootId 页面根节点
			 */
			clickRow:function(index,row){
				if(window.console){
					console.log('index:' + index)
									
				}
				var _config = sysmanMain.getCurrentModuConfig()	
				
				//点击为0cell
				if(_config.clickValue <= 0){
					return 
				}
				var _param = {depart_code:row.depart_code}
				var _data = private_method.getDateValue()
				
				if (_config.clickParam){					
					$.extend(_config.clickParam,_param,_data) 
				}else{
					_config.clickParam = _param
				}
				sysmanMain.setCurrentModuConfig(_config)
				
				var initQueryParams = {condition:_config.clickParam}
				
				
				sysmanMain.setModuConf('satisEvaluateDeptDetail',{initQueryParams:initQueryParams})
				
				public_method.openDetailPage()
			},
			
			openDetailPage:function(_options){
				var _config = {
					url : '/satisEvaluate/query/inPatientDeptDetailPage.action',
					window:'#' + window_id,
					width: 900,
					height: 700
				}
				//供应商质询
				var _param = {
					window:'#'+window_id,
					href:'/'+sysmanMain.getRootPath() + '/'+_config.url,
					width:_config.width,
					flag:false,
					height:_config.height,
					onClose:public_method.closePage
				}
				datagridServ.windowEdit(_param);
			},
			closePage:function(){
//				$('#'+window_id).empty();
			}
		}		
		
		var private_method = {
			getDateValue:function(){
					
					var _form = $('#'+ rootid +' form.condition-form ')
					var ret = formServ.getDataObj({
						rootId:rootid,
						form : $(_form)
					});
					return ret
				}
		}
		
		return public_method;
			
})